home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / DirectPlay / DXVBMessenger / Client / modDPlayClient.bas < prev    next >
Encoding:
BASIC Source File  |  2001-10-08  |  3.6 KB  |  125 lines

  1. Attribute VB_Name = "modDPlayClient"
  2. Option Explicit
  3. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  4. '
  5. '  Copyright (C) 1999-2001 Microsoft Corporation.  All Rights Reserved.
  6. '
  7. '  File:       modDplayClient.bas
  8. '
  9. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  10. 'Sleep declare
  11. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  12. 'Constants for the app
  13. Public Const gsAppName As String = "vbMessengerClient"
  14.  
  15. 'Public vars for the app
  16. Public dx As DirectX8
  17. Public dpc As DirectPlay8Client 'Client object
  18. Public dpa As DirectPlay8Address 'Local address
  19. Public dpas As DirectPlay8Address 'Host address
  20. Public gsUserName As String
  21. Public gsPass As String
  22. Public gsServerName As String
  23. Public gfConnected As Boolean
  24. Public gfCreatePlayer As Boolean
  25. Public gfLoggedIn As Boolean
  26. Public gofrmClient As frmClient
  27.  
  28. Public Sub InitDPlay()
  29.  
  30.     Cleanup 'Just in case
  31.     Set dx = New DirectX8
  32.     Set dpc = dx.DirectPlayClientCreate 'Create the client object
  33.     Set dpa = dx.DirectPlayAddressCreate 'Create an address
  34.     Set dpas = dx.DirectPlayAddressCreate 'Create the servers address object
  35.     
  36.     dpc.RegisterMessageHandler gofrmClient
  37.     
  38.     'Set up the local address
  39.     dpa.SetSP DP8SP_TCPIP
  40.     
  41.     'Set up the host address
  42.     dpas.SetSP DP8SP_TCPIP
  43.     dpas.AddComponentLong DPN_KEY_PORT, glDefaultPort
  44.     
  45. End Sub
  46.  
  47. Public Sub Cleanup()
  48.  
  49.     'Close may return DPNERR_UNINITIALIZED if we've already logged off, and we don't
  50.     'care, so lets ignore errors here.
  51.     On Error Resume Next
  52.     'Shut down our message handler
  53.     If Not dpc Is Nothing Then dpc.UnRegisterMessageHandler
  54.     'Close down our session
  55.     If Not dpc Is Nothing Then dpc.Close
  56.     Sleep 50 'Lets wait a small portion of time
  57.     DoEvents
  58.     Set dpc = Nothing
  59.     Set dpa = Nothing
  60.     Set dpas = Nothing
  61.     Set dx = Nothing
  62.     
  63. End Sub
  64.  
  65. Public Sub LogonPlayer()
  66.     Dim lMsg As Long, lOffset As Long
  67.     Dim oBuf() As Byte
  68.     
  69.     'The connect call has been completed.  Now we can send over our logon information
  70.     lOffset = NewBuffer(oBuf)
  71.     lMsg = Msg_Login
  72.     AddDataToBuffer oBuf, lMsg, LenB(lMsg), lOffset
  73.     AddStringToBuffer oBuf, gsUserName, lOffset
  74.     AddStringToBuffer oBuf, gsPass, lOffset
  75.     'Send the information
  76.     dpc.Send oBuf, 0, 0
  77.  
  78. End Sub
  79.  
  80. Public Sub CreatePlayer()
  81.     Dim lMsg As Long, lOffset As Long
  82.     Dim oBuf() As Byte
  83.     
  84.     'The connect call has been completed.  Now we can send over our logon information
  85.     lOffset = NewBuffer(oBuf)
  86.     lMsg = Msg_CreateNewAccount
  87.     AddDataToBuffer oBuf, lMsg, LenB(lMsg), lOffset
  88.     AddStringToBuffer oBuf, gsUserName, lOffset
  89.     AddStringToBuffer oBuf, gsPass, lOffset
  90.     'Send the information
  91.     dpc.Send oBuf, 0, 0
  92.  
  93. End Sub
  94.  
  95. Public Sub AddFriend(ByVal sFriend As String)
  96.     
  97.     Dim lMsg As Long, lOffset As Long
  98.     Dim oBuf() As Byte
  99.     
  100.     'Go ahead and add our friend
  101.     lOffset = NewBuffer(oBuf)
  102.     lMsg = Msg_AddFriend
  103.     AddDataToBuffer oBuf, lMsg, LenB(lMsg), lOffset
  104.     AddStringToBuffer oBuf, sFriend, lOffset
  105.     'Send the information
  106.     dpc.Send oBuf, 0, 0
  107.  
  108. End Sub
  109.  
  110. Public Sub BlockUser(ByVal sFriend As String)
  111.     
  112.     Dim lMsg As Long, lOffset As Long
  113.     Dim oBuf() As Byte
  114.     
  115.     'Go ahead and add our friend
  116.     lOffset = NewBuffer(oBuf)
  117.     lMsg = Msg_BlockFriend
  118.     AddDataToBuffer oBuf, lMsg, LenB(lMsg), lOffset
  119.     AddStringToBuffer oBuf, sFriend, lOffset
  120.     'Send the information
  121.     dpc.Send oBuf, 0, 0
  122.  
  123. End Sub
  124.  
  125.